package com.situ.day2;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ExceptionDemo {
    @Test
    public void test1() {
        try {
            System.out.println("try-1");
            FileInputStream fileInputStream = new FileInputStream("a.txt");
            fileInputStream.read();
            System.out.println("try-2");
        } catch (FileNotFoundException e) {
            System.out.println("catch");
            //throw new RuntimeException(e);
            e.printStackTrace();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            System.out.println("finally");
        }
        System.out.println("ExceptionDemo.test1");
    }

    @Test
    public void test3() {
        /*try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }*/
        try {
            show();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public void show() throws ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
    }

    @Test
    public void test33() {
        try {
            quQian(1200);
        } catch (MeiQianException e) {
            //throw new RuntimeException(e);
            e.printStackTrace();
        }
    }

    private void quQian(double money) throws MeiQianException {
        if (money >= 1000) {
            throw new MeiQianException("钱不够: " + money);
        }
        System.out.println("钱够了");
    }
}
